package org.acghub.mtdb.core.log;

import org.acghub.mtdb.core.*;

import java.util.Objects;

/**
 * @author zhouhe
 */
public final class LogSimple implements Log, Note, Verifyable {
    private final LogKey logkey;
    private final Object origin;
    private Runnable verify;

    public LogSimple(LogKey logKey, Object wrapped) {
        this.logkey = logKey;
        this.origin = wrapped;
    }

    @Override
    public void commit() {
        LogNotify.notify(logkey, this);
    }

    @Override
    public void rollback() {
        logkey.setValue(origin);
    }

    @Override
    public Runnable getVerify() {
        return verify;
    }

    @Override
    public void setVerify(Runnable verify) {
        this.verify = verify;
    }

    @Override
    public String toString() {
        return String.valueOf(origin);
    }

    @Override
    public boolean isEqual(Object o) {
        return Objects.equals(origin, o);
    }
}
